﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClusterAggregation.Datum
{
    public class CEuclideanDistanceSimilarityFunction: ISimilarity
    {
        public double[,] getMatrix(AData[] arg)
        {
            double[,] calc = new double[arg.Length,arg.Length];

            //first iteration
            for (int i = 0; i < arg.Length; i++)
            {
               
                for (int j = i; j < arg.Length; j++)
                {
                    calc[i, j] = similarity(arg[i], arg[j]);
                }
            }
            return calc;
        }

        public double[,] getFullMatrix(AData[] arg)
        {
            double[,] calc = new double[arg.Length, arg.Length];

            //CPixel[] tmp = (CPixel[])arg; // casting

            for (int i = 0; i < arg.Length; i++)
            {
                for (int j = 0; j < arg.Length; j++)
                {
                    calc[i,j] = similarity(arg[i], arg[j]);
                }
            }
            return calc;
        }

        public double similarity(AData a, AData b)
        {
            double sum = 0;
            for (int i = 0; i < a.coordinates.Length; i++)
                sum += (a.coordinates[i] - b.coordinates[i]) * (a.coordinates[i] - b.coordinates[i]);
            return Math.Sqrt(sum);
        }
    }
}
